<?php

class Action
{
    public function delivery_order() {
        $from = $to = $type = $only_delivery_note = null;

        extract(URLTracker::init(array(
            'from' => null,
            'to' => null,
            'type' => null,
            'only_delivery_note' => 1,
        )));

        if ($from) {
            $from = date('Y-m-d', strtotime($from)) . ' 00:00:00';
        }

        if ($to) {
            $to = date('Y-m-d', strtotime($to)) . ' 23:59:59';
        }

        $SQL = 'SELECT ' .
               join(',', array(
                   'o.`id`',
                   'o.`store_id`',
                   'o.`agency_id`',
                   'o.`type`',
                   'o.`progress`',
                   'o.`price`',
                   'o.`goods_num`',
                   'o.`pay_time`',
                   'o.`pay_user_money`',
                   'o.`payoff_time`',
                   'od.`status`',
                   'od.`return_cash`',
                   'od.`return_bbcoin`',
                   'od.`submit_time`',
                   'od.`verify_time`',
                   'od.`is_return_cash`',
                   'od.`return_cash_time`',
                   'od.`is_return_bbcoin`',
                   'od.`return_bbcoin_time`',
                   'u.`realname` "user_name"',
                   'u.`mobile` "user_mobile"',
                   'u2.`realname` "agency_name"',
                   'u2.`mobile` "agency_mobile"',
                   's.`title`',
                   's.`title_branch`',
               )) .
               ' FROM `order` o' .
               ' LEFT JOIN `order_delivery_note` od ON od.`order_id`= o.`id`' .
               ' LEFT JOIN `user` u ON o.`user_id`= u.`id`' .
               ' LEFT JOIN `user` u2 ON o.`agency_id`= u2.`id`' .
               ' LEFT JOIN `store` s ON o.`store_id`= s.`id`' .
               ' WHERE 1' .
               ($only_delivery_note ? ' AND o.`delivery_note_status` IS NOT NULL' : '') .
               ' AND u.`is_enable`=1' .
               ' AND s.`is_enable`=1' .
               ' AND o.`progress` != 15' .
               ($type ? ' AND o.`type` = ' . $type : '') .
               ($from ? ' AND o.`add_time` >= \'' . $from . '\'' : '') .
               ($to ? ' AND o.`add_time` <= \'' . $to . '\'' : '') .
               ' ORDER BY o.`type` ASC, od.`status` ASC, o.`add_time` DESC';

        $order_list = run_sql('order', 'getAll', $SQL);

        foreach ($order_list as $k => $v) {
            $v['order_number'] = order_helper::order_id_encode($v['id']);
            $v['status_info'] = $v['status'] ? order_config::$delivery_status[$v['status']] : '';
            $v['type'] = order_config::$order_type[$v['type']];
            $v['progress'] = order_config::$dealer_progress[$v['progress']];

            $v['title'] = str_replace("\n", '', $v['title']);

            if ($v['pay_time'] == '0000-00-00 00:00:00') {
                $v['pay_time'] = '';
            }
            if ($v['submit_time'] == '0000-00-00 00:00:00') {
                $v['submit_time'] = '';
            }
            if ($v['verify_time'] == '0000-00-00 00:00:00') {
                $v['verify_time'] = '';
            }
            if ($v['return_cash_time'] == '0000-00-00 00:00:00') {
                $v['return_cash_time'] = '';
            }
            if ($v['return_bbcoin_time'] == '0000-00-00 00:00:00') {
                $v['return_bbcoin_time'] = '';
            }

            $order_list[$k] = parse_param(array_fill_keys(array(
                'order_number',
                'id',
                'store_id',
                'agency_id',
                'type',
                'progress',
                'goods_num',
                'price',
                'pay_time',
                'pay_user_money',
                'status',
                'status_info',
                'return_cash',
                'return_bbcoin',
                'submit_time',
                'verify_time',
                'is_return_cash',
                'return_cash_time',
                'is_return_bbcoin',
                'return_bbcoin_time',
                'title',
                'title_branch',
                'user_name',
                'user_mobile',
                'agency_name',
                'agency_mobile',
            ), ''), $v);
        }

        array_unshift($order_list, array(
            '订单号',
            '订单id',
            '门店ID',
            '合伙人ID',
            '订单类型',
            '订单状态',
            '商品数量',
            '订单总价',
            '支付时间',
            '余额支付',
            '送货单状态',
            '送货单状态描述',
            '将返余额',
            '将返抱抱币',
            '送货单上传时间',
            '审批时间(二审)',
            '是否返余额',
            '余额返还时间',
            '是否返还抱抱币',
            '抱抱币返还时间',
            '门店',
            '门店后缀',
            '掌柜',
            '掌柜手机',
            '合伙人',
            '合伙人手机',
        ));
        // var_dump($order_list);
        //_widget('tools.csv')->export('export', $order_list);
        _widget('tools.excel')->export('export', array(
            array(
                'name' => '订单列表',
                'data' => array(
                    'data' => $order_list,
                ),
            )
        ));
    }

    public function device_order() {

        $from = $to = $type = $pay_user_money = null;

        extract(URLTracker::init(array(
            'from' => null,
            'to' => null,
            'type' => null,
            'pay_user_money' => 0,
        )));

        if ($from) {
            $from = date('Y-m-d', strtotime($from)) . ' 00:00:00';
        }

        if ($to) {
            $to = date('Y-m-d', strtotime($to)) . ' 23:59:59';
        }

        $goods_ids = goods_helper::get_goods_ids_by_category_ids(24);

        $SQL = 'SELECT ' .
               join(',', array(
                   'o.`id`',
               )) .
               ' FROM `order` o' .
               ' LEFT JOIN `order_relation` ore ON ore.`order_id`= o.`id`' .
               ' WHERE 1' .
               ' AND o.`progress` != 15' .
               ($pay_user_money ? ' AND o.`pay_user_money` > 0' : '') .
               ($type ? ' AND o.`type` = ' . $type : '') .
               ($from ? ' AND o.`add_time` >= \'' . $from . '\'' : '') .
               ($to ? ' AND o.`add_time` <= \'' . $to . '\'' : '') .
               ' AND ore.goods_id IN (' .
               join(',', $goods_ids) .
               ')' .
               ' GROUP BY o.`id`';

        $res = run_sql('order', 'getAll', $SQL);

        $order_ids = array();
        foreach ($res as $v) {
            $order_ids[] = $v['id'];
        }

        $res = null;
        unset($res);

        $filter = array();
        // 有效的
        $filter['is_enable'] = 1;

        // 下单时间
        if ($from) {
            $filter['add_time >='] = $from;
        }
        if ($to) {
            $filter['add_time <='] = $to;
        }
        if ($type) {
            $filter['type'] = $type;
        }

        if (!empty($order_ids)) {
            $filter['id'] = $order_ids;
        }

        $order_list = _model('order')->getList(enable_filter($filter), ' ORDER BY `id` ASC');

        foreach ($order_list as $k => $v) {
            $order_list[$k]['order_relation'] = _model('order_relation')->getList(array(
                'order_id' => $v['id'],
                'status' => 1,
                'goods_id' => $goods_ids,
            ));
            // 送货单明细
            // $order_list[$k]['order_delivery_note'] = order_helper::get_order_delivery_note_info_by_order_id($v['id']);
            // 合伙人
            if ($v['type'] == 1) {
                $order_list[$k]['dealer_info'] = user_helper::get_user_info($v['user_id']);
            } else {
                $order_list[$k]['dealer_info'] = user_helper::get_user_info($v['agency_id']);
            }
            // 门店
            $order_list[$k]['store_info'] = store_helper::get_store_info($v['store_id']);
        }

        $list = $order_list;
        $order_list = null;
        unset($order_list);

        //初始化excel对象
        $objPHPExcel = new PHPExcel();
        $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
        //设置当前的sheet索引，用于后续的内容操纵
        $objPHPExcel->setActiveSheetIndex(0);
        $objActSheet = $objPHPExcel->getActiveSheet();

        // 哪几列
        $col_arr = array();
        // 第一排的标题
        $col_title_arr = array(
            '序号',
            '订单编号',
            '总数量',
            '总价',
            '商家信息',
            '杯型信息(杯)',
            '订单类型',
            '订单状态',
            '支付方式',
            '余额支付',
            '门店',
            '门店ID',
            '省',
            '市',
            '区',
            '合伙人',
            '合伙人手机'
        );

        $col_content_arr = array(
            'number',
            'order_id',
            'sum',
            'price',
            'store_info',
            'cup_info',
            'order_type',
            'progress',
            'pay_type',
            'pay_user_money',
            'store_name',
            'store_id',
            'province',
            'city',
            'county',
            'agency',
            'agency_mobile'
        );

        //获取电影商品列表
        $goods_info = _model('goods')->getList(array('id' => $goods_ids, 'is_sale' => 1, 'status' => 1));
        $goods_detail = array();
        foreach ($col_title_arr as $k => $v) {
            $abc = cinema_helper::excel_column_encode($k);
            array_push($col_arr, $abc);
        }
        $attach_row = array('-单价(元)', '-实际需支付(元)', '-数量');
        foreach ($goods_info as $k => $v) {
            $one_goods_detail = array();
            foreach ($attach_row as $k1 => $v1) {
                array_push($col_title_arr, $v['title'] . $v1);
                $abc = cinema_helper::excel_column_encode(count($col_arr));
                array_push($col_arr, $abc);

                if ($one_goods_detail) {
                    array_push($one_goods_detail, array($abc));
                } else {
                    $one_goods_detail = array($abc);
                }

                array_push($col_content_arr, $abc);
            }
            $goods_detail[$v['id']] = $one_goods_detail;
        }


        // 设置文档属性
        foreach ($col_arr as $k => $v) {
            //设置4个列的宽度
            if (in_array($v, array('A'))) {
                $objActSheet->getColumnDimension($v)->setWidth(8);
            } else {
                $objActSheet->getColumnDimension($v)->setWidth(20);
            }
            //设置单位格内容A1,B1,C1,D1
            $objActSheet->setCellValue($v . "1", $col_title_arr[$k]);
            //格式化数字为字符串，避免导致数字默认右对齐单元格
            //            $objActSheet->getStyle($v)->getNumberFormat()->setFormatCode("@");
            //设置自动换行
            $objActSheet->getStyle($v)->getAlignment()->setWrapText(true);
        }

        // 填充单元格
        $key = 2;
        foreach ($list as $k => $v) {

            $order_type_list = order_config::$order_type;
            $cup_name_list = cup_config::$cup_type;
            $pay_type_list = order_config::$pay_type;
            $order_progress = order_config::$dealer_progress;
            $store_info = store_helper::get_store($v['store_id']);
            $zzb_info = array();

            if ($store_info['zzb_id'] > 0) {
                $zzb_info = cinema_helper::get_cinema_info_by_id($store_info['zzb_id']);
            }

            // 先将合并的信息填入excl
            foreach ($col_arr as $k2 => $v2) {
                $place = $v2 . $key;
                $col_content = $col_content_arr[$k2];
                $value = '0';

                if ($col_content == 'order_id') {
                    $value = order_helper::order_id_encode($v['id']);
                }
                if ($col_content == 'price') {
                    $value = $v['price'];
                }
                if ($col_content == 'pay_type') {
                    $value = $pay_type_list[$v['pay_type']];
                }
                if ($col_content == 'sum') {
                    //订单总商品数
                    $value = $v['goods_num'];
                }
                if ($col_content == 'store_info') {
                    // 商家信息
                    $user_info = user_helper::get_user_info($v['user_id']);
                    $value = "收货人：" . $user_info['realname'] . "\r手机号码：" . $user_info['mobile'];
                }
                if ($col_content == 'cup_info') {
                    // 杯型信息
                    $cup_list_info = cup_helper::get_order_cup_data($v['id']);
                    if (!$cup_list_info) {
                        $value = '0';
                    } else {
                        $value = '';
                        foreach ($cup_list_info as $cup_k => $cup_v) {
                            $value .= $cup_name_list[$cup_v['cup_type']] . '：' . $cup_v['true_cup_num'] . "\r";
                        }
                    }
                }
                if ($col_content == 'order_type') {
                    $value = $order_type_list[$v['type']];
                }
                if ($col_content == 'progress') {
                    $value = $order_progress[$v['progress']];
                }
                if ($col_content == 'number') {
                    $value = $k + 1;
                }
                if ($col_content == 'store_name') {
                    $value = $v['store_info']['title'] . ' - ' . $v['store_info']['title_branch'];
                }
                if ($col_content == 'agency') {
                    $value = $v['dealer_info']['realname'];
                }
                if ($col_content == 'agency_mobile') {
                    $value = $v['dealer_info']['mobile'];
                }
                if ($col_content == 'store_id') {
                    $value = $v['store_id'];
                }
                if ($col_content == 'province') {
                    $province_info = area_helper::get_area_info($store_info['province_id']);
                    if ($province_info) {
                        $value = $province_info['area'];
                    } else {
                        if ($zzb_info) {
                            $value = $zzb_info['province'];
                        }
                    }
                }
                if ($col_content == 'city') {
                    $city_info = area_helper::get_area_info($store_info['city_id']);
                    if ($city_info) {
                        $value = $city_info['area'];
                    } else {
                        if ($zzb_info) {
                            $value = $zzb_info['city'];
                        }
                    }
                }
                if ($col_content == 'county') {
                    $county_info = area_helper::get_area_info($store_info['district_id']);
                    if ($county_info) {
                        $value = $county_info['area'];
                    } else {
                        if ($zzb_info) {
                            $value = $zzb_info['county'];
                        }
                    }
                }

                if ($col_content == 'pay_user_money') {
                    $value = $v['pay_user_money'];
                }

                $objActSheet->setCellValue($place, $value);
                usleep(100);
            }


            foreach ($v['order_relation'] as $r_k => $order_relation_info) {

                $one_goods_id = $order_relation_info['goods_id'];
                $one_goods_price = array(
                    $order_relation_info['goods_price'],
                    $order_relation_info['real_price'],
                    $order_relation_info['goods_num']
                );
                foreach ($attach_row as $kt => $vt) {

                    if (isset($goods_detail[$one_goods_id][$kt])) {
                        if (is_array($goods_detail[$one_goods_id][$kt])) {
                            $row_id = $goods_detail[$one_goods_id][$kt][0];
                        } else {
                            $row_id = $goods_detail[$one_goods_id][$kt];
                        }
                    }

                    $objActSheet->setCellValue($row_id . $key, $one_goods_price[$kt]);
                }
            }


            $key++;

            usleep(100);
        }

        //设置页面类型
        header("Content-Type: application/vnd.ms-excel");
        //用于下载的文件头
        header("Content-Type: application/force-download");
        header("Content-Type: application/download");
        header("Content-Type: application/octet-stream");

        //$title = trim($catebirthday_gift_recordry_name."表").".xls";
        $title = date('Y-m-d') . "影院订单明细.xls";
        // ff正常，ie不正常，下面是从网站找到的解决方案
        if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) {
            $title = rawurlencode($title);
        }
        header("Content-Disposition: attachment; filename=" . $title);
        header("Content-Transfer-Encoding: binary");
        //最后修改时间
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
        //不使用缓存
        header('Cache-Control: ust-revalidate, post-check=0, pre-check=0');
        header('Cache-Control: public');
        header("Expires: 0");
        header("Pragma: public");
        $objWriter->save('php://output');
        exit;
    }

    public function store_order() {

        $date = an_request('date', date('Y-m-d', strtotime('-1 day')));

        $filter = array();

        // 下单时间
        $filter['add_time >='] = $date . ' 00:00:00';

        $filter['add_time <='] = $date . ' 23:59:59';

        $filter['status'] = 1;
        // added type filter by ninghx 用来区分总部订单、经销商订单还是影院订单
        $filter['type'] = 5;

        $order_count = _model('order')->getTotal(enable_filter($filter));

        if ($order_count) {

            $order_by = ' ORDER BY `id` DESC ';

            $order_list = _model('order')->getList(enable_filter($filter), $order_by);

            foreach ($order_list as $k => $v) {
                $order_list[$k]['order_relation'] = _model('order_relation')->getList(array(
                    'order_id' => $v['id'],
                    'status' => 1
                ));
                // 送货单明细
                $order_list[$k]['order_delivery_note'] = order_helper::get_order_delivery_note_info_by_order_id($v['id']);
                // 合伙人
                $order_list[$k]['dealer_info'] = user_helper::get_user_info($v['agency_id']);
            }

            $this->export_excel($date, $order_list);
        }
    }

    /**
     * 用户订单表
     */
    public function export_excel($date, $list = array()) {
        //初始化excel对象
        $objPHPExcel = new PHPExcel();
        $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
        //设置当前的sheet索引，用于后续的内容操纵
        $objPHPExcel->setActiveSheetIndex(0);
        $objActSheet = $objPHPExcel->getActiveSheet();

        // 哪几列
        $col_arr = array();
        // 第一排的标题
        $col_title_arr = array(
            '序号',
            '订单编号',
            '总数量',
            '总价',
            '商家信息',
            '杯型信息(杯)',
            '订单类型',
            '订单状态',
            '支付方式',
            '门店名称',
            '门店id',
            '省',
            '市',
            '区',
            '合伙人',
            '合伙人手机'
        );

        $col_content_arr = array(
            'number',
            'order_id',
            'sum',
            'price',
            'store_info',
            'cup_info',
            'order_type',
            'progress',
            'pay_type',
            'store_name',
            'store_id',
            'province',
            'city',
            'county',
            'agency',
            'agency_mobile'
        );

        $goods_info = _model('goods')->getList(array('is_sale' => 1, 'status' => 1));
        $goods_detail = array();
        foreach ($col_title_arr as $k => $v) {
            $abc = cinema_helper::excel_column_encode($k);
            array_push($col_arr, $abc);
        }
        $attach_row = array('-单价(元)', '-实际需支付(元)', '-数量');
        foreach ($goods_info as $k => $v) {
            $one_goods_detail = array();
            foreach ($attach_row as $k1 => $v1) {
                array_push($col_title_arr, $v['title'] . $v1);
                $abc = cinema_helper::excel_column_encode(count($col_arr));
                array_push($col_arr, $abc);

                if ($one_goods_detail) {
                    array_push($one_goods_detail, array($abc));
                } else {
                    $one_goods_detail = array($abc);
                }

                array_push($col_content_arr, $abc);
            }
            $goods_detail[$v['id']] = $one_goods_detail;
        }

        // 设置文档属性
        foreach ($col_arr as $k => $v) {
            //设置4个列的宽度
            if (in_array($v, array('A'))) {
                $objActSheet->getColumnDimension($v)->setWidth(8);
            } else {
                $objActSheet->getColumnDimension($v)->setWidth(20);
            }
            //设置单位格内容A1,B1,C1,D1
            $objActSheet->setCellValue($v . "1", $col_title_arr[$k]);
            //格式化数字为字符串，避免导致数字默认右对齐单元格
            //            $objActSheet->getStyle($v)->getNumberFormat()->setFormatCode("@");
            //设置自动换行
            $objActSheet->getStyle($v)->getAlignment()->setWrapText(true);
        }

        // 填充单元格
        $key = 2;
        foreach ($list as $k => $v) {

            $order_type_list = order_config::$order_type;
            $cup_name_list = cup_config::$cup_type;
            $pay_type_list = order_config::$pay_type;
            $order_progress = order_config::$store_progress;
            $store_info = store_helper::get_store($v['store_id']);
            $zzb_info = array();

            if ($store_info['zzb_id'] > 0) {
                $zzb_info = cinema_helper::get_cinema_info_by_id($store_info['zzb_id']);
            }

            // 先将合并的信息填入excl
            foreach ($col_arr as $k2 => $v2) {
                $place = $v2 . $key;
                $col_content = $col_content_arr[$k2];
                $value = '0';


                if ($col_content == 'order_id') {
                    $value = order_helper::order_id_encode($v['id']);
                }
                if ($col_content == 'price') {
                    $value = $v['price'];
                }
                if ($col_content == 'pay_type') {
                    $value = $pay_type_list[$v['pay_type']];
                }
                if ($col_content == 'sum') {
                    //订单总商品数
                    $value = $v['goods_num'];
                }
                if ($col_content == 'store_info') {
                    // 商家信息
                    $user_info = user_helper::get_user_info($v['user_id']);
                    $value = "收货人：" . $user_info['realname'] . "\r手机号码：" . $user_info['mobile'];
                }
                if ($col_content == 'cup_info') {
                    // 杯型信息
                    $cup_list_info = cup_helper::get_order_cup_data($v['id']);
                    if (!$cup_list_info) {
                        $value = '0';
                    } else {
                        $value = '';
                        foreach ($cup_list_info as $cup_k => $cup_v) {
                            $value .= $cup_name_list[$cup_v['cup_type']] . '：' . $cup_v['true_cup_num'] . "\r";
                        }
                    }
                }
                if ($col_content == 'order_type') {
                    $value = $order_type_list[$v['type']];
                }
                if ($col_content == 'progress') {
                    $value = $order_progress[$v['progress']];
                }
                if ($col_content == 'number') {
                    $value = $k + 1;
                }
                if ($col_content == 'store_name') {
                    $user_role_id = user_helper::get_user_role_id($v['user_id']);
                    if ($user_role_id == user_config::STORE_MANAGER || $user_role_id == user_config::STORE_OWNER) {
                        $store_info = store_helper::get_store($v['store_id']);
                        $cinema_info = cinema_helper::get_cinema_info_by_id($store_info['zzb_id']);
                        if ($cinema_info) {
                            $value = $cinema_info['cinema_name'];
                        } else {
                            $value = $store_info['title'] . ' - ' . $store_info['title_branch'];
                        }
                    }
                }
                if ($col_content == 'agency') {
                    $user_info = user_helper::get_user_info($v['agency_id']);
                    $value = $user_info['realname'];
                }
                if ($col_content == 'agency_mobile') {
                    $user_info = user_helper::get_user_info($v['agency_id']);
                    $value = $user_info['mobile'];
                }
                if ($col_content == 'store_id') {
                    $value = $v['store_id'];
                }
                if ($col_content == 'province') {
                    $province_info = area_helper::get_area_info($store_info['province_id']);
                    if ($province_info) {
                        $value = $province_info['area'];
                    } else {
                        if ($zzb_info) {
                            $value = $zzb_info['province'];
                        }
                    }
                }
                if ($col_content == 'city') {
                    $city_info = area_helper::get_area_info($store_info['city_id']);
                    if ($city_info) {
                        $value = $city_info['area'];
                    } else {
                        if ($zzb_info) {
                            $value = $zzb_info['city'];
                        }
                    }
                }
                if ($col_content == 'county') {
                    $county_info = area_helper::get_area_info($store_info['district_id']);
                    if ($county_info) {
                        $value = $county_info['area'];
                    } else {
                        if ($zzb_info) {
                            $value = $zzb_info['county'];
                        }
                    }
                }

                $objActSheet->setCellValue($place, $value);
            }


            foreach ($v['order_relation'] as $r_k => $order_relation_info) {

                $one_goods_id = $order_relation_info['goods_id'];
                $one_goods_price = array(
                    $order_relation_info['goods_price'],
                    $order_relation_info['real_price'],
                    $order_relation_info['goods_num']
                );
                foreach ($attach_row as $kt => $vt) {

                    if (isset($goods_detail[$one_goods_id][$kt])) {
                        if (is_array($goods_detail[$one_goods_id][$kt])) {
                            $row_id = $goods_detail[$one_goods_id][$kt][0];
                        } else {
                            $row_id = $goods_detail[$one_goods_id][$kt];
                        }
                    }

                    $objActSheet->setCellValue($row_id . $key, $one_goods_price[$kt]);
                }
            }

            $key++;

        }

        //设置页面类型
        header("Content-Type: application/vnd.ms-excel");
        //用于下载的文件头
        header("Content-Type: application/force-download");
        header("Content-Type: application/download");
        header("Content-Type: application/octet-stream");

        //$title = trim($catebirthday_gift_recordry_name."表").".xls";
        $title = date('Y-m-d', strtotime($date)) . "门店订单明细.xls";
        // ff正常，ie不正常，下面是从网站找到的解决方案
        if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) {
            $title = rawurlencode($title);
        }
        header("Content-Disposition: attachment; filename=" . $title);
        header("Content-Transfer-Encoding: binary");
        //最后修改时间
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
        //不使用缓存
        header('Cache-Control: ust-revalidate, post-check=0, pre-check=0');
        header('Cache-Control: public');
        header("Expires: 0");
        header("Pragma: public");
        $objWriter->save('php://output');
        exit;
    }
}

?>